package com.cmpe.group6.storyroad.ListAdapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cmpe.group6.storyroad.R;
import com.cmpe.group6.storyroad.jsonClasses.NotificationObject;

/** List adapter for notification list on the main page.
 *
 */
public class NotificationsAdapter extends BaseAdapter {
	Context context;
	List<NotificationObject> rowItems;

	/**
	 * @param context Current context.
	 * @param items Notification Objects.
	 */
	public NotificationsAdapter(Context context, List<NotificationObject> items) {
		this.context = context;
		this.rowItems = items;
	}

	/** ViewHolder class for quicker generation.
	 *
	 */
	private class ViewHolder {
		TextView txtTitle;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.rowItems.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub

		if (this.rowItems.get(position).isStory()) {
			return this.rowItems.get(position).getContentId();
		} else {
			return this.rowItems.get(position).getUsername();
		}
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;

		LayoutInflater mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.notif_item, null);
			holder = new ViewHolder();
			holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		String item = rowItems.get(position).getMessage();

		holder.txtTitle.setText(item);

		return convertView;
	}

}
